package cn.stylefeng.guns.sys.modular.system.service;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.sys.modular.system.entity.ImUser;
import cn.stylefeng.guns.sys.modular.system.entity.Role;
import cn.stylefeng.guns.sys.modular.system.mapper.ImUserMapper;
import cn.stylefeng.roses.core.util.ToolUtil;
import cn.stylefeng.roses.kernel.model.exception.RequestEmptyException;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;
import java.util.Map;

@Service
public class ImUserService extends ServiceImpl<ImUserMapper, ImUser> {

    /**
     * 根据条件查询imuser列表
     *
     * @return
     * @date 2017年2月12日 下午9:14:34
     */
    public Page<Map<String, Object>> selectImUsers(String condition) {
        Page page = LayuiPageFactory.defaultPage();
        return this.baseMapper.selectImUsers(page, condition);
    }

    /**
     * 获取imuser列表
     *
     * @author fengshuonan
     * @Date 2019-08-30 15:35
     */
    public IPage listImUser(String name) {
        Page pageContext = LayuiPageFactory.defaultPage();
        return baseMapper.listImUser(pageContext, name);
    }

    /**
     * 添加角色
     *
     * @author fengshuonan
     * @Date 2018/12/23 6:40 PM
     */
    @Transactional(rollbackFor = Exception.class)
    public void addImuser(ImUser imUser) {

        if (ToolUtil.isOneEmpty(imUser, imUser.getName(), imUser.getAccount(), imUser.getPassword())) {
            throw new RequestEmptyException();
        }

        imUser.setCreateTime(new Date());
        imUser.setUpdateTime(new Date());
        imUser.setStatus(0);

        this.save(imUser);
    }


}
